<?php

class youhui_comment_list
{
public function index()
{
$root = array();
$root['return'] = 1;
$yh_id = intval($GLOBALS['request']['yh_id']);
$merchant_id = intval($GLOBALS['request']['merchant_id']);
$content = addslashes(trim($GLOBALS['request']['content']));
if ($content != null &&$content != ''){
$email = addslashes($GLOBALS['request']['email']);
$pwd = addslashes($GLOBALS['request']['pwd']);
$user = user_check($email,$pwd);
$user_id  = intval($user['id']);
$rel_table = 'youhui';
$rel_id = $yh_id;
if($yh_id == 0) {
$rel_id = $merchant_id;
$rel_table = 'supplier_location';
}else{
}
$merchant_youhui_comment = array(
'user_id'=>$user_id,
'rel_id'=>$rel_id,
'rel_table'=>$rel_table,
'title'=>$content,
'content'=>$content,
'is_effect'=>1,
'create_time'=>get_gmtime(),
);
$GLOBALS['db']->autoExecute(DB_PREFIX.'message',$merchant_youhui_comment,'INSERT');
$id = $GLOBALS['db']->insert_id();
$root['id'] = $id;
if($id >0)
{
$root['status'] = 1;
$root['info'] = '添加成功';
}else{
$root['status'] = 0;
$root['info'] = '添加失败';
}
}
$page = intval($GLOBALS['request']['page']);
$page=$page==0?1:$page;
$page_size = PAGE_SIZE;
$limit = (($page-1)*$page_size).','.$page_size;
$sql_count = 'select count(*) from '.DB_PREFIX.'message as a '.
' left outer join '.DB_PREFIX.'youhui as b on b.id = a.rel_id '.
' left outer join '.DB_PREFIX.'user as c on c.id = a.user_id ';
$sql = 'select a.id, a.rel_id as yh_id, a.content,a.create_time, c.user_name from '.DB_PREFIX.'message as a '.
' left outer join '.DB_PREFIX.'user as c on c.id = a.user_id ';
$where = ' a.is_effect = 1 ';
if ($merchant_id >0)			
$where .= " and a.rel_table = 'supplier_location' and a.rel_id = $merchant_id";
if ($yh_id >0)
$where .= " and a.rel_table = 'youhui' and a.rel_id = $yh_id";
$sql_count.=' where '.$where;
$sql.=' where '.$where.' order by a.create_time desc';
$sql.=' limit '.$limit;
$total = $GLOBALS['db']->getOne($sql_count);
$page_total = ceil($total/$page_size);
$list = $GLOBALS['db']->getAll($sql);
$youhui_comment_list = array();
foreach($list as $item){
$youhui_comment_list[] = array('id'=>$item['id'],
'yh_id'=>$item['yh_id'],
'content'=>trim($item['content']),
'user_name'=>trim($item['user_name']),
'create_time'=>$item['create_time'],
'create_time_format'=>getBeforeTimelag($item['create_time'])
);
}
$root['item'] = $youhui_comment_list;
$root['page'] = array('page'=>$page,'page_total'=>$page_total);
output($root);
}
}
?>